//
//  XQBaseTableListArrowCell.m
//  JoinPeso
//
//  Created by 小琦 on 2024/11/21.
//

#import "XQBaseTableListArrowCell.h"

@interface XQBaseTableListArrowCell()
@property (nonatomic,strong) UIView *bgView;
@property (nonatomic,strong) UILabel *lb;
@property (nonatomic,strong) UIButton *btn;
@end

@implementation XQBaseTableListArrowCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = [UIColor clearColor];
        [self makeUI];
        [self makeConstraints];
    }
    return self;
}

- (void)makeUI {
    [self.contentView addSubview:self.bgView];
    [self.bgView addSubview:self.lb];
    [self.bgView addSubview:self.btn];
}

- (void)makeConstraints {
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(@0);
        make.bottom.equalTo(@-29);
    }];
    
    [self.btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@0);
        make.top.equalTo(@0);
        make.height.mas_equalTo(23);
        make.width.mas_equalTo(53);
    }];
    
    [self.lb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.btn);
        make.left.equalTo(@20);
    }];
}

#pragma mark - setter

- (void)setTitle:(NSString *)title {
    self.lb.text = title;
}

- (void)setBottomPadding:(CGFloat)bottomPadding {
    [self.bgView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(-bottomPadding);
    }];
}

#pragma mark - private

- (void)btnClick {
    if (self.btnHandle) {
        self.btnHandle();
    }
}

#pragma mark - lazy

- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [[UIView alloc] init];
    }
    return _bgView;
}

- (UILabel *)lb {
    if (!_lb) {
        _lb = [[UILabel alloc] init];
        _lb.textColor = kBlackTextColor;
        _lb.font = [UIFont boldSystemFontOfSize:15];
    }
    return _lb;
}

- (UIButton *)btn {
    if (!_btn) {
        _btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_btn setImage:[UIImage imageNamed:@"user_arrow"] forState:UIControlStateNormal];
        [_btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _btn;
}
@end
